package com.lepu.app.main.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lepu.pasm.R;

public class SimpleListAdapter extends BaseAdapter {

	private LayoutInflater mLayoutInflater = null;
	@SuppressWarnings("unused")
	private Context mContext = null;
	private ArrayList<String> mArrayList = null;

	public SimpleListAdapter(Context context, ArrayList<String> arrayList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mArrayList = arrayList;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (mArrayList != null && mArrayList.size() > 0) {
			size = mArrayList.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.main_simple_list_item, null);

			holder = new ViewHolder();
			
			TextView titleTextView = (TextView) convertView.findViewById(R.id.titleTextView);
			
			holder.titleTextView = titleTextView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		String item = mArrayList.get(position);
		
		holder.titleTextView.setText(item);

		return convertView;
	}

	private static class ViewHolder {
		TextView titleTextView;
	}
}
